package com.camel.iamfx;

import com.camel.iamfx.config.ApplicationConfig;
import com.camel.iamfx.config.Config;
import com.xwintop.xcore.javafx.dialog.FxAlerts;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import java.util.ResourceBundle;

public class IamFxApplication extends Application {

    public static ResourceBundle RESOURCE_BUNDLE;

    private ApplicationConfig config;

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/index.fxml"));
        primaryStage.setTitle("IAM");
        primaryStage.setScene(new Scene(root, 1500, 800));
        primaryStage.show();
        primaryStage.setOnCloseRequest(this::confirmExit);

    }

    private void confirmExit(Event event) {
        if (FxAlerts.confirmYesNo("退出应用", "确定要退出吗？")) {
            doExit();
        } else if (event != null) {
            event.consume();
        }
    }

    private void doExit() {
//        StageUtils.savePrimaryStageBound(stage);
        Platform.exit();
        System.exit(0);
    }

    public static void main(String[] args) {
        launch(args);
    }

}
